package com.daocheng.weblog.common.domain.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.daocheng.weblog.common.config.InsertBatchMapper;
import com.daocheng.weblog.common.domain.dos.ArticleCategoryRelDO;
import com.daocheng.weblog.common.domain.dos.ArticleTagRelDO;

import java.util.List;

/**
 * @ClassName ArticleTagRelMapper
 * @author: 稻城
 * @date: 2025/3/11
 * @Version 1.0
 * @description: TODO
 */
public interface ArticleTagRelMapper extends InsertBatchMapper<ArticleTagRelDO> {
    default int deleteByArticleId(Long articleId) {
        return delete(Wrappers.<ArticleTagRelDO>lambdaQuery().eq(ArticleTagRelDO::getArticleId, articleId));
    }

    default List<ArticleTagRelDO> selectByArticleId(Long articleId) {
        return selectList(Wrappers.<ArticleTagRelDO>lambdaQuery().eq(ArticleTagRelDO::getArticleId, articleId));
    }

    /**
     * @param tagId
     * @return ArticleTagRelDO
     * @author 稻城
     * @Date 2025/3/12 17:30
     * @description 校验标签下是否有文章
     */
    default ArticleTagRelDO selectOneByTagId(Long tagId) {
        return selectOne(Wrappers.<ArticleTagRelDO>lambdaQuery().eq(ArticleTagRelDO::getTagId, tagId).last("LIMIT 1"));
    }

    /**
      * @author 稻城
      * @Date 2025/3/12 20:37
      * @param articleIds
      * @return List<ArticleTagRelDO>
      * @description 根据文章 ID 集合批量查询
      */
    default List<ArticleTagRelDO> selectByArticleIds(List<Long> articleIds) {
        return selectList(Wrappers.<ArticleTagRelDO>lambdaQuery()
                .in(ArticleTagRelDO::getArticleId, articleIds));
    }
    /**
     * 查询该标签 ID 下所有关联记录
     * @param tagId
     * @return
     */
    default List<ArticleTagRelDO> selectByTagId(Long tagId) {
        return selectList(Wrappers.<ArticleTagRelDO>lambdaQuery()
                .eq(ArticleTagRelDO::getTagId, tagId));
    }
}
